//TAB切换
var ROOT;
function resetVerifyCode(){
	var timenow = new Date().getTime();
	document.getElementById('verifyImage').src= '/index.php?g=Home&m=Index&a=verify#'+timenow;
}
function resetVerifyCode2(){
	var timenow = new Date().getTime();
	document.getElementById('verifyImage2').src= '/index.php?g=Home&m=Index&a=verify#'+timenow;
}

function donghua(obj){
	  var speed=20;
	  var demoh  =  document.getElementById(obj);
	  var demoh1 =  document.getElementById(obj+'_1');
	  var demoh2 =  document.getElementById(obj+'_2');
	  demoh2.innerHTML=demoh1.innerHTML;
	  function wfdh(){
		  if(demoh2.offsetWidth-demoh.scrollLeft<=0){demoh.scrollLeft-=demoh1.offsetWidth;}
		  if(demoh2.offsetWidth-demoh.scrollLeft>0){demoh.scrollLeft++;}
	  }
	  var MyMarh=setInterval(wfdh,speed);
	  demoh.onmouseover=function() {clearInterval(MyMarh);}
	  demoh.onmouseout=function() {MyMarh=setInterval(wfdh,speed);}
}

function showon(obj,onobj,id){
	$(obj+' '+ onobj).click(function(){
 		//$(this).parent().addClass('on').siblings().removeClass('on');
		if($(this).parent().hasClass('on')){
			$(this).parent().removeClass('on');
		}else{
			$(this).parent().addClass('on');
		}
	});
	if(id){
		$('#catlist_'+id).parent().parent().addClass('on');	
	}
}

function Floaters() {
		this.delta=0.15;
		this.playid =null;
		this.items	= [];
		this.addItem	= function(id,x,y,content) {
			var newItem = {};
			newItem.object = document.getElementById(id);

			if(x==0){
				objw= newItem.object.offsetWidth;
				var body = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
				newItem.x = x = body.scrollLeft + (body.clientWidth - objw)/2;
				newItem.y = y;
			}else{
				newItem.x = x;
				newItem.y = y;
			}

			this.items[this.items.length]		= newItem;
		}
		this.play =function(varname){
			this.playid = setInterval(varname+'.plays()',30);
		}
		this.close = function(obj){
			document.getElementById(obj).style.display='none';
			 //clearInterval(this.playid);
		}
}
Floaters.prototype.plays = function(){
	var diffY;
	if (document.documentElement && document.documentElement.scrollTop)
	{
		diffY = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		diffY = document.body.scrollTop;
	}else{}

	for(var i=0;i<this.items.length;i++) {
		var obj = this.items[i].object;
		var followObj_y = this.items[i].y;
		var total = diffY + followObj_y;
		if(this.items[i].x >= 0){
			obj.style['left'] = this.items[i].x+ 'px';
		}else{
			obj.style['right'] = Math.abs(this.items[i].x)+ 'px';
		}
		if( obj.offsetTop != total)
		{
			var oldy = (total - obj.offsetTop) * this.delta;
				newtop = obj.offsetTop + ( oldy>0?1:-1 ) * Math.ceil( Math.abs(oldy) );
			obj.style['top'] = newtop + 'px';
		}
	}
}


function changeorder(obj,moduleid,id,doit,ordercall){
	var objs  =  document.getElementById(obj);
	var datas={'moduleid':moduleid,'id': id,'num':objs.value};
	$.ajax({
		type:"POST",
		url: "/index.php?m=Order&a=ajax&do="+doit,
		data: datas,
		timeout:"6000",
		dataType:"JSON",
		success: function(data){
			if(data.data==1){
				ordercall.call(this,obj,moduleid,id,doit,data);
			}else{
				alert(' 加入购物车失败:'+data.msg);
			}			
		},
		error:function(){
			alert("网络不稳定,请重新尝试!");
		}
	});
}


function area_change(id,level,province,city,area,provinceid,cityid,areaid){
	var datas={'level':level,'provinceid':provinceid,'cityid':cityid,'areaid':areaid};
	$.ajax({
		type:"POST",
		url: "/index.php?g=Home&m=Ajax&a=Area&id="+id,
		data: datas,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(level==0){
			$('#'+province).html(data.province);
			$('#'+city).html(data.city);
			$('#'+area).html(data.area);
			}else if(level==1){
			$('#'+city).html(data.city);
			$('#'+area).html(data.area);
			}else if(level==2){
				$('#'+area).html(data.area);
			}
		},
		error:function(){
			alert("网络不给力，省份城市加载失败，请刷新页面重新尝试！");
		}
	}); 
}

//设为首页
function SetHome(obj,url){
    try{
        obj.style.behavior='url(#default#homepage)';
       obj.setHomePage(url);
   }catch(e){
       if(window.netscape){
          try{
              netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         }catch(e){
              alert("抱歉，此操作被浏览器拒绝！\n\n请在浏览器地址栏输入'about:config'并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
          }
       }else{
        alert("抱歉，您所使用的浏览器无法完成此操作。\n\n您需要手动将【"+url+"】设置为首页。");
       }
  }
} 

//收藏本站
function AddFavorite(title, url) {
  try {
      window.external.addFavorite(url, title);
  }
catch (e) {
     try {
       window.sidebar.addPanel(title, url, "");
    }
     catch (e) {
         alert("抱歉，您所使用的浏览器无法完成此操作。\n\n加入收藏失败，请使用Ctrl+D进行添加");
     }
  }
}

/***************
*等比缩放图片大小
*宽高可以不指定，在JS中默认200*200(可改)
*用法：
<img onLoad="ResizeImg(this,'120','200')"
**************/
function ResizeImg(Img,width,height)
{
    var image=new Image(); 
    image.src=Img.src; 
	if(width>0 && height>0){
		if(image.width>width||image.height>height) 
		{
			w=image.width/width;
			h=image.height/height;
			if(w>h){
				Img.width=width;
				Img.height=image.height/w;
			}else{
				Img.height=height;
				Img.width=image.width/h;
			}
		}
	}
	else{
		if(width>0 && height==0){
			if(image.width>width) 
			{
				Img.width=width;
			}
		}
		if(height>0 && width==0){
			if(image.height>height) 
			{
				Img.height=height;				
			}
		}
	}
    
}
/**************
*整个DIV图片自动缩小方法。
*用法：

<div id="d">
	<img src="p1.gif" />
	<img src="p2.gif" />
</div>

<script>
addEventSimple(window,'load',onloadResizeImg);
function onloadResizeImg(){
	ResizeImgByID('d',50,50);
}
</script>
**************/
function ResizeImgByID(contentId,maxWidth,maxHeight){
	var imgs=document.getElementById(contentId).getElementsByTagName("img");
	for(var i=0;i<imgs.length;i++){
		ResizeImg(imgs[i],maxWidth,maxHeight);
	}
}



function user_insert(id,level,province,city,provinceid,cityid,prosstr){
	var datas={'level':level,'provinceid':provinceid,'cityid':cityid};
	$.ajax({
		type:"POST",
		url: "/index.php?g=User&m=Ajax&a=procat&id="+id,
		data: datas,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(level==0){
				$('#'+province).html(data.province);
				$('#'+city).html(data.city);
			}
			else if(level==1){
				$('#'+city).html(data.city);
				pro_standard(id,prosstr);
			}
		},
		error:function(){
			alert("网络不给力，栏目品牌加载失败，请刷新页面重新尝试！");
		}
	}); 
}

function pro_standard(id,prosstr){
	var datas={'p_standard':prosstr};
	$.ajax({
		type:"POST",
		url: "/index.php?g=User&m=Ajax&a=standard&id="+id,
		data: datas,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			$('#prostandard').html(data.htmlstr);
			$('#idlist').val(data.idlist);
			$('#scount').val(data.count);
		},
		error:function(){
			alert("网络不给力，栏目品牌加载失败，请刷新页面重新尝试！");
		}
	}); 
}

function createstandard2(){
	var idlist=$("#idlist").val();
	var scount=$("#scount").val();
	var protype=$("#protype").val();
	ida=idlist.split(",");
	var htmlstr = new Array(scount);
	var rowsnum_arr= new Array(scount);
	var contentstr="";
	var rowsnum=1;
	
	for(i=0;i<scount;i++){
		htmlstr[i]="";
		rowsnum_arr[i]=0;
		if($("#sta_"+ida[i]+"_t").val()==1){
			var t=0;
			$("input[type='checkbox'][name='sta_"+ida[i]+"']").each(function(){//反选
				if($(this).attr("checked")){
					if(t==0){
						htmlstr[i]=$(this).val();
					}
					else{
						htmlstr[i]+="@"+$(this).val();
					}	
					t++;		
				}
			})
		}
		else{
			if($("input[type='text'][name='sta_"+ida[i]+"']").val().indexOf(";") > 0 )
			{
				htmlstr[i]=$("input[type='text'][name='sta_"+ida[i]+"']").val().split(";").join("@");
			}
			else{
				htmlstr[i]=$("input[type='text'][name='sta_"+ida[i]+"']").val();
			}
		}
		rowsnum_arr[i]=htmlstr[i].split("@").length;
		rowsnum=rowsnum*rowsnum_arr[i];
		$('#stasel_'+ida[i]).val(htmlstr[i]);	
	}
	contentstr+="<table width='100%' border='0' cellspacing='0' cellpadding='0' >";
	contentstr+="<thead>";
	contentstr+="<tr>";
	for(i=0;i<scount;i++){
		contentstr+="<td>"+$("#sta_"+ida[i]+"_n").val()+"</td>";
	}
	if(protype!=1){
		contentstr+="<td>在线价格<i class='red_font'>*</i></td>";
	}
		contentstr+="<td>体验券价格<i class='red_font'>*</i></td>";
        contentstr+="<td>数量<i class='red_font'>*</i></td>";
	contentstr+="</tr>";
	contentstr+="</thead>";
	contentstr+="<tbody>";
	
	if(scount>1){
		if(rowsnum_arr[0]==1){
			itemname=""
			jgid=0;
			if(htmlstr[0].indexOf("|") > 0 ){
				itemname=htmlstr[0].split("|")[1];
				jgid=htmlstr[0].split("|")[0];
			}
			else{
				itemname=htmlstr[0];
				jgid=0;
			}
			for(m=0;m<rowsnum_arr[1];m++){
				contentstr+="<tr>"
				temp2=htmlstr[1].split("@");
				itemname2=""
				jgid2=0;
				if(temp2[m].indexOf("|") > 0 ){
					itemname2=temp2[m].split("|")[1];
					jgid2=temp2[m].split("|")[0];
				}
				else{
					itemname2=temp2[m];
					jgid2=m;
				}
				if(m==0){
					contentstr+="<td rowspan='"+rowsnum_arr[1]+"' valign='middle'>"+itemname+"</td>";
				}				
				contentstr+="<td>"+itemname2+"</td>";
				if(protype!=1){
					contentstr+="<td><input type='text' name='price_"+jgid+"_"+jgid2+"' /></td>";
				}
				contentstr+="<td><input type='text' name='point_"+jgid+"_"+jgid2+"' /></td>";
				contentstr+="<td><input type='text' name='stock_"+jgid+"_"+jgid2+"' /></td>";
				contentstr+="</tr>"
			}
		}
		else if(rowsnum_arr[0]>1){
			for(n=0;n<rowsnum_arr[0];n++){
				temp=htmlstr[0].split("@");
				itemname=""
				jgid=0;
				if(temp[n].indexOf("|") > 0 ){
					itemname=temp[n].split("|")[1];
					jgid=temp[n].split("|")[0];
				}
				else{
					itemname=temp[n];
					jgid=n;
				}
				for(m=0;m<rowsnum_arr[1];m++){
					contentstr+="<tr>"
					temp2=htmlstr[1].split("@");
					itemname2=""
					jgid2=0;
					if(temp2[m].indexOf("|") > 0 ){
						itemname2=temp2[m].split("|")[1];
						jgid2=temp2[m].split("|")[0];
					}
					else{
						itemname2=temp2[m];
						jgid2=m;
					}
					if(m==0){
						contentstr+="<td rowspan='"+rowsnum_arr[1]+"' valign='middle'>"+itemname+"</td>";
					}				
					contentstr+="<td>"+itemname2+"</td>";
					if(protype!=1){
						contentstr+="<td><input type='text' name='price_"+jgid+"_"+jgid2+"' /></td>";
					}
					contentstr+="<td><input type='text' name='point_"+jgid+"_"+jgid2+"' /></td>";
					contentstr+="<td><input type='text' name='stock_"+jgid+"_"+jgid2+"' /></td>";
					contentstr+="</tr>"
				}	
			}
		}
		else{
			
		}
	}
	else if(scount==1){
		for(n=0;n<rowsnum_arr[0];n++){
			temp=htmlstr[0].split("@");
			itemname=""
			jgid=0;
			if(temp[n].indexOf("|") > 0 ){
				itemname=temp[n].split("|")[1];
				jgid=temp[n].split("|")[0];
			}
			else{
				itemname=temp[n];
				jgid=n;
			}
			contentstr+="<tr>"
			contentstr+="<td>"+itemname+"</td>";
			if(protype!=1){
				contentstr+="<td><input type='text' name='price_"+jgid+"' /></td>";
			}
			contentstr+="<td><input type='text' name='point_"+jgid+"' /></td>";
			contentstr+="<td><input type='text' name='stock_"+jgid+"' /></td>";
			contentstr+="</tr>"
		}
	}
	else{
		alert("请选择商品规格!");
	}
	
	
	
	contentstr+="</tbody>";
	contentstr+="</table>";
	$('#pricelist').html(contentstr);
}
/**************
*只允许输入数字和小数点。
*用法：
<input type=text  onkeyup="ClearNoNum(this)"/>
**************/
function ClearNoNum(obj){
	obj.value = obj.value.replace(/[^\d.]/g,"");
	obj.value = obj.value.replace(/^\./g,"");
	obj.value = obj.value.replace(/\.{2,}/g,".");
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
function ClearNoNum2(obj){
	obj.value = obj.value.replace(/[^\d]/g,"");
	
}
//根据规格显示价格
function prostandardsel(pid,bid,sid){
	$("#sta_a_"+bid+"_"+sid).addClass("sop_select");
	$("#sta_a_"+bid+"_"+sid).parents("li").siblings("li").children("a").removeClass("sop_select");
	$("#sta_a_"+bid+"_"+sid).children("i").addClass("sop_selected");
	$("#sta_a_"+bid+"_"+sid).parents("li").siblings("li").children("a").children("i").removeClass("sop_selected");
	$("#s_"+bid).val(sid);
	$("#jgsn_"+bid).html('"'+$("#sta_span_"+bid+"_"+sid).html()+'"');
	
	var idlist=$("#prostaidlist").val();
	arr=idlist.split(",");
	var flag=true;
	for(i=0;i<arr.length;i++){
		if($("#s_"+arr[i]).val()==""){
			flag=false;	
		}
	}
	if(flag){
		showproprice(pid,idlist);	
	}
}

//根据规格显示价格
function protypeshowprice(n){
	$("#jgsatprosel"+n).children("a").addClass("sop_select");
	$("#jgsatprosel"+n).siblings("li").children("a").removeClass("sop_select");
	$("#jgsatprosel"+n).children("a").children("i").addClass("sop_selected");
	$("#jgsatprosel"+n).siblings("li").children("a").children("i").removeClass("sop_selected");
	$("#jgbuyprotype").val(n);
	var excnum=$("#jgpropoint").val();
	var tatolpoint=0;
	if(n==1){
		$('#jgsn_type').html("“在线价格”");
		tatolpoint=$("#jgproprice").val()*excnum;
		$("#jgshowproprice").html($("#jgproprice").val());
	}
	else if(n==2){
		$('#jgsn_type').html("“体验券价格”");
		tatolpoint=$("#jgprodjqprice").val()*excnum;
		$("#jgshowproprice").html($("#jgprodjqprice").val());
	}
	$('#jgshowpropoint').html(tatolpoint);
}
function showproprice(id,str){	
	var excnum=$("#jgpropoint").val();
	var tatolpoint=0;
	arr=str.split(",");
	valstr="";
	for(i=0;i<arr.length;i++){
		if(i==0){
			valstr=$("#s_"+arr[i]).val();
		}
		else{
			valstr+=","+$("#s_"+arr[i]).val();
		}
	}
	var datas={'idlist':str,'selval':valstr,'buytype':$("#jgbuyprotype").val()};
	$.ajax({
		type:"POST",
		url: "/index.php?g=Home&m=Ajax&a=showproprice&id="+id,
		data: datas,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(data.ok=="no"){
				alert(data.msg);
			}
			else{
				$('#jgproprice').val(data.price);
				$('#jgprodjqprice').val(data.point);
				$('#jgprostock').val(data.stock);	
				if($("#jgbuyprotype").val()==1){
					$('#jgshowproprice').html(data.price);
					tatolpoint=data.price*excnum;
				}
				else{
					$('#jgshowproprice').html(data.point);
					tatolpoint=data.point*excnum;
				}
				//$('#jgshowpropoint').html(data.point);
				$('#jgshowpropoint').html(tatolpoint);
				$('#jgshowprostock').html(data.stock);				
			}
		},
		error:function(){
			alert("网络不给力，商品价格加载失败，请刷新页面重新尝试！");
		}
	});	
}

function jgaddmun(n){
	buyname=$("#buynum").val()*1;
	jgprostock=$("#jgprostock").val()*1
	if(n==1){
		if(buyname>=jgprostock){
			$("#buynum").val(jgprostock);
			return ;
		}
	}
	else if(n==0){
		if(buyname>jgprostock){
			$("#buynum").val(jgprostock);
			return ;
		}
		else if(buyname<1){
			$("#buynum").val(1);
			return ;
		}
	}
	else{
		if(buyname<2){
			$("#buynum").val(1);	
			return ;
		}
	}
	$("#buynum").val(buyname+(n*1))
}

function jgsharelikeadd(id){	
	$.ajax({
		type:"POST",
		url: "/index.php?g=Home&m=Ajax&a=usersharelike&id="+id,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(data.ok=="no"){
				alert(data.msg);
			}
			else{
				$('#jglike').html("（"+data.val+"）");		
			}
		},
		error:function(){
			alert("网络不给力，羡慕+1失败，请刷新页面重新尝试！");
		}
	});
}

function fastLogin(){
	var un=$("#ksloginusername").val();
	var pw=$("#ksloginuserpwd").val();
	var ucode=$("#kslogincode").val();
	var datas={'un':un,'pw':pw,'ucode':ucode};
	$.ajax({
		type:"POST",
		url: "/index.php?g=User&m=Ajax&a=fastLogin",
		data: datas,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(data.ok=="no"){
				$('#fastloginmsg').html(data.msg);
			}
			else{
				location.reload();		
			}
		},
		error:function(){
			alert("网络不给力，请刷新页面重新尝试！");
		}
	});
}

function changeuserlist(n,pid){
	var p=$("#jgchoosepage").val();
	var pages=p*1+n*1;
	if(pages<2){
		pages=1;
	}
	$.ajax({
		type:"POST",
		url: "/index.php?g=Home&m=Ajax&a=getUserlist&p="+pages+"&pid="+pid,
		timeout:"8000",
		dataType:"JSON",
		success: function(data){
			if(data.msg=="yes"){
				$('#jgbox_showul').html(data.con);
				$("#jgchoosepage").val(pages);
			}
		},
		error:function(){
			alert("网络不给力，会员列表加载失败，请刷新页面重新尝试！");
		}
	});
}